﻿package mortal.game.manager.msgTip
{
    import com.gengine.global.*;
    import com.gengine.utils.*;
    import com.greensock.*;
    import com.greensock.easing.*;
    import com.mui.controls.*;
    import com.mui.core.*;
    import com.mui.display.*;
    import flash.display.*;
    import flash.filters.*;
    import flash.geom.*;
    import flash.text.*;
    import flash.utils.*;
    import mortal.common.*;
    import mortal.common.font.*;
    import mortal.component.gconst.*;
    import mortal.game.manager.*;

    public class RollTipsBmpItem extends Sprite
    {
        private var _msg:String;
        private var _type:MsgRollTipsType;
        private var _hideCall:Function;
        private var _rollTween:TweenMax;
        private var _iconBmp:Bitmap;
        private var _textField:GTextFiled;
        private var _bmp:Bitmap;
        private var _bmpd:BitmapData;
        private var _timeKey:uint;
        private var _inTween:TweenMax;
        private var _outTween:TweenMax;
        private var _filterTween:Boolean;
        private var _matrix:Matrix;
        private var _glowFilter:GlowFilter;

        public function RollTipsBmpItem()
        {
            this.initUI();
            return;
        }// end function

        private function initUI() : void
        {
            mouseEnabled = false;
            mouseChildren = false;
            this._glowFilter = new GlowFilter(16777215, 0.6, 16, 16, 2, 1);
            this._matrix = new Matrix();
            this._matrix.tx = 45;
            this._matrix.ty = 5;
            this._bmp = new Bitmap();
            addChild(this._bmp);
            this._iconBmp = new Bitmap();
            addChild(this._iconBmp);
            this._textField = new GTextFiled();
            this._textField.selectable = false;
            this._textField.width = 320;
            this._textField.height = 24;
            this._textField.filters = [FilterConst.nameGlowFilter];
            var _loc_1:* = new GTextFormat(FontUtil.defaultName, 13, 12002609, false, null, null, null, null, TextFormatAlign.LEFT);
            _loc_1.letterSpacing = 2;
            this._textField.defaultTextFormat = _loc_1;
            this._textField.autoSize = TextFieldAutoSize.LEFT;
            this._textField.multiline = true;
            this._textField.wordWrap = true;
            return;
        }// end function

        private function onInEnd() : void
        {
            clearTimeout(this._timeKey);
            this._timeKey = setTimeout(this.onTimeOut, 600);
            return;
        }// end function

        private function onTimeOut() : void
        {
            this._outTween = TweenMax.to(this, 0.5, {alpha:0, ease:Linear.easeInOut(30, 400, 3, 40), onComplete:this.onOutEnd});
            return;
        }// end function

        private function onOutEnd() : void
        {
            if (this._hideCall != null)
            {
                this._hideCall.call(this, this);
            }
            return;
        }// end function

        public function get msg() : String
        {
            return this._msg;
        }// end function

        public function filterTips() : void
        {
            if (this._outTween && this._outTween.active)
            {
                this._outTween.kill();
                this._outTween = null;
            }
            clearTimeout(this._timeKey);
            if (!this._filterTween)
            {
                this._filterTween = true;
                this.alpha = 1;
                this.filters = null;
                EffectManager.glowFilterReg(this, [this._glowFilter], 5, 10, 0, 4, this.onFilterEnd);
            }
            return;
        }// end function

        private function onFilterEnd() : void
        {
            this._filterTween = false;
            this.onInEnd();
            return;
        }// end function

        public function moveTo(param1:int, param2:Boolean) : void
        {
            var _loc_3:Number = NaN;
            if (this._rollTween && this._rollTween.active)
            {
                this._rollTween.kill();
            }
            if (param2)
            {
                _loc_3 = 0.5;
                if (param1 > y)
                {
                    _loc_3 = 0.3;
                }
                this._rollTween = TweenMax.to(this, _loc_3, {y:param1});
            }
            else
            {
                this.y = param1;
            }
            return;
        }// end function

        public function updateData(param1:String, param2:MsgRollTipsType, param3:Function) : void
        {
            var _loc_7:ScaleBitmap = null;
            this._msg = param1;
            this._type = param2;
            this._hideCall = param3;
            this._iconBmp.bitmapData = GlobalClass.getBitmapData(param2.iconName);
            this._textField.width = Global.stage.stageWidth / 2 - 160 - 35;
            this._textField.htmlText = HTMLUtil.addColor(param1, param2.color);
            this._textField.y = 0;
            this._textField.alpha = 1;
            if (this._bmpd)
            {
                this._bmpd.dispose();
                this._bmpd = null;
            }
            var _loc_4:* = GlobalClass.getBitmapData(param2.bgName).height;
            var _loc_5:* = this._textField.textWidth + 80;
            var _loc_6:* = Math.max(_loc_4, this._textField.textHeight + 14);
            this._matrix.ty = 5;
            this._bmpd = new BitmapData(_loc_5, _loc_6, true, 16777215);
            _loc_7 = ResourceConst.getScaleBitmap(param2.bgName);
            _loc_7.width = _loc_5;
            _loc_7.height = _loc_6;
            this._bmpd.draw(_loc_7);
            this._bmpd.draw(this._textField, this._matrix);
            this._bmp.bitmapData = this._bmpd;
            this._bmp.x = _loc_4 > 30 ? (0) : (-15);
            this._bmp.y = int((this._iconBmp.height - this._bmp.height) / 2);
            _loc_7.dispose();
            this.alpha = 0.5;
            this._inTween = TweenMax.to(this, 0.5, {alpha:1, ease:Linear.easeInOut(30, 400, 3, 40), onComplete:this.onInEnd});
            return;
        }// end function

        public function dispose() : void
        {
            if (this._inTween)
            {
                this._inTween.kill();
                this._inTween = null;
            }
            if (this._outTween)
            {
                this._outTween.kill();
                this._outTween = null;
            }
            if (this._rollTween)
            {
                this._rollTween.kill();
                this._rollTween = null;
            }
            clearTimeout(this._timeKey);
            this._hideCall = null;
            this._bmp.bitmapData.dispose();
            this._textField.text = "";
            this._filterTween = false;
            EffectManager.glowFilterUnReg(this);
            this.alpha = 1;
            this.y = 0;
            return;
        }// end function

    }
}
